package com.kaifamiao.www.IP.do0928;

import java.io.*;

public class Demo {

    public static void main(String[] args) {
            String source = "E:\\kaifamiao\\上课\\d0922\\20220922-04-AM01.mp4";
            String directry ="E:\\kaifamiao\\上课\\d0922\\test";
            int size = 1024*1024*20;
        System.out.println(cutter(source,size,directry));

    }

    public static int cutter(String source,int size,String directry){
        int count = 0;
        File file = new File(source);
        if (file.isFile()&&size>0){
            //读取文件
            try (
                    FileInputStream fis = new FileInputStream(file);
            ){
                byte[] bytes = new byte[size];
                int len = -1;
                //存放剪切后文件的地址
                File parent = new File(directry);
                if (!parent.exists()){
                    parent.mkdirs();
                }
                while ((len=fis.read(bytes))!=-1){
                    File out = new File(directry, count++ + ".temp");
                    FileOutputStream fileOutputStream = new FileOutputStream(out);
                    fileOutputStream.write(bytes,0,len);
                    fileOutputStream.close();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return count;
    }

}
